import React, { useMemo, useCallback } from 'react';
import City from './../../city/City';

interface IProps {
  value: string[];
  id: string;
  onChange(value: any[], id: string): void;
  isSelectCounty?: boolean; // 是否可选择县区一级
}

export default ({ value, id, isSelectCounty, onChange }: IProps) => {

  const handleValue = useMemo(() => {
    if(Array.isArray(value)) return value.filter(item => item);
    return []
  }, [value]);

  const _onChange = useCallback((value) => {
    onChange(value, id);
  }, [id, onChange])

  return (
    <City value={handleValue} onChange={_onChange} isSelectCounty={isSelectCounty}/>
  )
}